home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / GRAHAM / XAAES_S.ZIP / XAAES / SCRLWIDG.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-06  |  13.7 KB  |  474 lines

  1. /*
  2.  * XaAES - XaAES Ain't the AES
  3.  *
  4.  * A multitasking AES replacement for MiNT
  5.  *
  6.  */
  7.  
  8. #include <OSBIND.H>
  9. #include <VDI.H>
  10. #include <memory.h>
  11. #include "XA_TYPES.H"
  12. #include "XA_DEFS.H"
  13. #include "XA_GLOBL.H"
  14. #include "KERNAL.H"
  15. #include "K_DEFS.H"
  16. #include "BOX3D.H"
  17. #include "KERNAL.H"
  18. #include "DRAG_BOX.H"
  19. #include "GRAF_MOU.H"
  20. #include "MESSAGES.H"
  21. #include "C_WINDOW.H"
  22. #include "RECTLIST.H"
  23. #include "ALL_WIDG.H"
  24. #include "STD_WIDG.H"
  25.  
  26. /*
  27.     Scroll bar & Slider handlers
  28. */
  29.  
  30. /*======================================================
  31.     LEFT SCROLL WIDGET BEHAVIOUR
  32. ========================================================*/
  33. short display_lscroll(XA_WINDOW *wind, XA_WIDGET *widg)
  34. {
  35.     short x,y;
  36.  
  37.     rp_2_ap(wind, widg, &x, &y);    /* Convert relative coords and window location to absolute screen location */
  38.  
  39.     if (widg->stat==XAW_PLAIN)
  40.         display_widget_bitmap(x, y, widget_bitmap_left);
  41.     else
  42.         display_widget_bitmap(x, y, widget_bitmap_left_s);
  43.  
  44.     return TRUE;
  45. }
  46.  
  47. short click_lscroll(XA_WINDOW *wind, XA_WIDGET *widg)
  48. {
  49.     short mx,my,mb;
  50.     
  51.     send_app_message(wind->owner, WM_ARROWED, 0, wind->handle, WA_LFLINE, 0, 0, 0);
  52.     vq_mouse(V_handle, &mb, &mx, &my);
  53.  
  54.     if (mb)    /* If the button has been held down, set a pending/active widget for the client */
  55.     {
  56.         set_widget_active(wind, widg, &click_lscroll);
  57.         return FALSE;    /* We return false here so the widget display status stays selected whilst it repeats */
  58.     }
  59.     cancel_widget_active(wind);
  60.     return TRUE;
  61. }
  62.  
  63. /*======================================================
  64.     RIGHT SCROLL WIDGET BEHAVIOUR
  65. ========================================================*/
  66. short display_rscroll(XA_WINDOW *wind, XA_WIDGET *widg)
  67. {
  68.     short x,y;
  69.  
  70.     rp_2_ap(wind, widg, &x, &y);    /* Convert relative coords and window location to absolute screen location */
  71.  
  72.     if (widg->stat==XAW_PLAIN)
  73.         display_widget_bitmap(x, y, widget_bitmap_right);
  74.     else
  75.         display_widget_bitmap(x, y, widget_bitmap_right_s);
  76.  
  77.     return TRUE;
  78. }
  79.  
  80. short click_rscroll(XA_WINDOW *wind, XA_WIDGET *widg)
  81. {
  82.     short mx,my,mb;
  83.     
  84.     send_app_message(wind->owner, WM_ARROWED, 0, wind->handle, WA_RTLINE, 0, 0, 0);
  85.     vq_mouse(V_handle, &mb, &mx, &my);
  86.  
  87.     if (mb)    /* If the button has been held down, set a pending/active widget for the client */
  88.     {
  89.         set_widget_active(wind, widg, &click_rscroll);
  90.         return FALSE;    /* We return false here so the widget display status stays selected whilst it repeats */
  91.     }
  92.     cancel_widget_active(wind);
  93.     return TRUE;
  94. }
  95.  
  96. /*======================================================
  97.     UP SCROLL WIDGET BEHAVIOUR
  98. ========================================================*/
  99. short display_uscroll(XA_WINDOW *wind, XA_WIDGET *widg)
  100. {
  101.     short x,y;
  102.  
  103.     rp_2_ap(wind, widg, &x, &y);    /* Convert relative coords and window location to absolute screen location */
  104.  
  105.     if (widg->stat==XAW_PLAIN)
  106.         display_widget_bitmap(x, y, widget_bitmap_up);
  107.     else
  108.         display_widget_bitmap(x, y, widget_bitmap_up_s);
  109.  
  110.     return TRUE;
  111. }
  112.  
  113. short click_uscroll(XA_WINDOW *wind, XA_WIDGET *widg)
  114. {
  115.     short mx,my,mb;
  116.     
  117.     send_app_message(wind->owner, WM_ARROWED, 0, wind->handle, WA_UPLINE, 0, 0, 0);
  118.     vq_mouse(V_handle, &mb, &mx, &my);
  119.  
  120.     if (mb)    /* If the button has been held down, set a pending/active widget for the client */
  121.     {
  122.         set_widget_active(wind, widg, &click_uscroll);
  123.         return FALSE;    /* We return false here so the widget display status stays selected whilst it repeats */
  124.     }
  125.     cancel_widget_active(wind);
  126.     return TRUE;
  127. }
  128.  
  129. /*======================================================
  130.     DOWN SCROLL WIDGET BEHAVIOUR
  131. ========================================================*/
  132. short display_dscroll(XA_WINDOW *wind, XA_WIDGET *widg)
  133. {
  134.     short x,y;
  135.  
  136.     rp_2_ap(wind, widg, &x, &y);    /* Convert relative coords and window location to absolute screen location */
  137.  
  138.     if (widg->stat==XAW_PLAIN)
  139.         display_widget_bitmap(x, y, widget_bitmap_down);
  140.     else
  141.         display_widget_bitmap(x, y, widget_bitmap_down_s);
  142.  
  143.     return TRUE;
  144. }
  145.  
  146. short click_dscroll(XA_WINDOW *wind, XA_WIDGET *widg)
  147. {
  148.     short mx,my,mb;
  149.     
  150.     send_app_message(wind->owner, WM_ARROWED, 0, wind->handle, WA_DNLINE, 0, 0, 0);
  151.     vq_mouse(V_handle, &mb, &mx, &my);
  152.  
  153.     if (mb)    /* If the button has been held down, set a pending/active widget for the client */
  154.     {
  155.         set_widget_active(wind, widg, &click_dscroll);
  156.         return FALSE;    /* We return false here so the widget display status stays selected whilst it repeats */
  157.     }
  158.     cancel_widget_active(wind);
  159.     return TRUE;
  160. }
  161.  
  162. /*======================================================
  163.     VERTICAL SLIDER WIDGET BEHAVIOUR
  164.     The slider widgets are slightly more complex than other widgets
  165.     as they have three seperate 'widgets' inside them.
  166.     (I know GEM doesn't have these, but I think they're cool)
  167. ========================================================*/
  168. short display_vslide(XA_WINDOW *wind, XA_WIDGET *widg)
  169. {
  170.     short x,y,pnt[6],offs,len;
  171.     XA_SLIDER_WIDGET *sl=(XA_SLIDER_WIDGET*)(widg->stuff);
  172.  
  173.     rp_2_ap(wind, widg, &x, &y);    /* Convert relative coords and window location to absolute screen location */
  174.  
  175.     len=(widg->h*sl->length)/1000;
  176.     offs=((widg->h - len)*sl->position)/1000;
  177.  
  178.     if (widg->stat==XAW_PLAIN)
  179.         vsl_color(V_handle,display.dial_colours.t_l_col);
  180.     else
  181.         vsl_color(V_handle,display.dial_colours.b_r_col);
  182.     
  183.     pnt[0]=x+widg->w; pnt[1]=y+offs;
  184.     pnt[2]=x; pnt[3]=y+offs;
  185.     pnt[4]=x; pnt[5]=y+offs+len;
  186.     v_pline(V_handle,3,pnt);
  187.  
  188.     if (widg->stat==XAW_PLAIN)
  189.         vsl_color(V_handle,display.dial_colours.b_r_col);
  190.     else
  191.         vsl_color(V_handle,display.dial_colours.t_l_col);
  192.  
  193.     pnt[2]=x+widg->w; pnt[3]=y+offs+len;
  194.     v_pline(V_handle,3,pnt);
  195.     
  196.     return TRUE;
  197. }
  198.  
  199. short drag_vslide(XA_WINDOW *wind, XA_WIDGET *widg)
  200. {
  201.     short pmx,pmy,mx,my,mb,x,y,wcy,dy;
  202.     short imx,imy,pnt[4],clip[4],offs,noffs,len,orig_offs;
  203.     XA_SLIDER_WIDGET *sl=(XA_SLIDER_WIDGET*)(widg->stuff);
  204. #if JOHAN_RECTANGLES
  205.     XA_RECT_LIST *rl, *drl;
  206. #else
  207.     XA_RECT_LIST *rl=generate_rect_list(wind);
  208.     XA_RECT_LIST *drl;
  209. #endif
  210.  
  211. #if JOHAN_RECTANGLES
  212.     if (!(rl = wind->rl_full))
  213.         rl = wind->rl_full = generate_rect_list(wind);
  214. #endif
  215.  
  216.     rp_2_ap(wind, widg, &x, &y);    /* Convert relative coords and window location to absolute screen location */
  217.     pnt[0]=x; pnt[1]=y;
  218.     pnt[2]=x+widg->w; pnt[3]=y+widg->h;
  219.     vsf_color(V_handle,display.dial_colours.bg_col);
  220.     vsf_interior(V_handle,FIS_SOLID);
  221.  
  222.     len=(widg->h*sl->length)/1000;
  223.     orig_offs=offs=sl->position;
  224.     wcy=widg->click_y-((widg->h - len)*sl->position)/1000;
  225.  
  226.     vq_mouse(V_handle, &mb, &imx, &imy);
  227.     pmx=imx; pmy=imy;
  228.  
  229.     if ((mb)&((wcy>0)&&(wcy<len)))            /* Drag slider */
  230.     {
  231.         do {
  232.             vq_mouse(V_handle, &mb, &mx, &my);
  233.             if (my!=pmy)            /* Has mouse moved? */
  234.             {
  235.                 dy=(1000*(my-pmy))/(widg->h-len);
  236.                 noffs=offs+dy;
  237.                 if (noffs<0) noffs=0;
  238.                 if (noffs>1000) noffs=1000;
  239.  
  240.                 if (noffs!=offs)    /* Has the slider moved? */
  241.                 {
  242.                     v_hide_c(V_handle);
  243.                     for(drl=rl; drl; drl=drl->next)                /* Walk the rectangle list */
  244.                     {
  245.                         clip[0]=drl->x; clip[1]=drl->y;
  246.                         clip[2]=drl->x+drl->w; clip[3]=drl->y+drl->h;
  247.                         vs_clip(V_handle,1, clip);
  248.                         v_bar(V_handle,pnt);
  249.                     }
  250.                     offs=noffs;
  251.                     sl->position=offs;
  252.                     for(drl=rl; drl; drl=drl->next)                /* Walk the rectangle list */
  253.                     {
  254.                         clip[0]=drl->x; clip[1]=drl->y;
  255.                         clip[2]=drl->x+drl->w; clip[3]=drl->y+drl->h;
  256.                         vs_clip(V_handle,1, clip);
  257.                         display_vslide(wind, widg);
  258.                     }
  259.                     v_show_c(V_handle, 1);
  260.                 }
  261.                 pmy=my;
  262.             }
  263.         } while(mb);
  264.  
  265.         sl->position=orig_offs;
  266.         send_app_message(wind->owner, WM_VSLID, 0, wind->handle, offs, 0, 0, 0);
  267.     }else{
  268.         vsf_color(V_handle,display.dial_colours.highlight_col);
  269.         if (wcy<0)                    /* Page left */
  270.         {
  271.             send_app_message(wind->owner, WM_ARROWED, 0, wind->handle, WA_UPPAGE, 0, 0, 0);
  272.             pnt[0]=x; pnt[1]=y;
  273.             pnt[2]=x+widg->w; pnt[3]=y+(widg->h - len)*sl->position/1000;
  274.         }else{                    /* Page right */
  275.             send_app_message(wind->owner, WM_ARROWED, 0, wind->handle, WA_DNPAGE, 0, 0, 0);
  276.             pnt[0]=x; pnt[1]=y+(widg->h - len)*sl->position/1000+len;
  277.             pnt[2]=x+widg->w; pnt[3]=y+widg->h;
  278.         }
  279.         v_hide_c(V_handle);
  280.         for(drl=rl; drl; drl=drl->next)                /* Walk the rectangle list */
  281.         {
  282.             clip[0]=drl->x; clip[1]=drl->y;
  283.             clip[2]=drl->x+drl->w; clip[3]=drl->y+drl->h;
  284.             vs_clip(V_handle,1, clip);
  285.             v_bar(V_handle,pnt);
  286.             display_vslide(wind, widg);
  287.         }
  288.         v_show_c(V_handle, 1);
  289.         vsf_color(V_handle,display.dial_colours.bg_col);
  290.         if (mb)    /* If the button has been held down, set a pending/active widget for the client */
  291.         {
  292.             set_widget_active(wind, widg, &drag_vslide);
  293.             return FALSE;    /* We return false here so the widget display status stays selected whilst it repeats */
  294.         }
  295.         cancel_widget_active(wind);
  296.     }
  297.     
  298.     v_hide_c(V_handle);
  299.     while(rl)        /* Dispose of the rectangle list & erase the dragged slider */
  300.     {
  301.         drl=rl;
  302.         clip[0]=drl->x; clip[1]=drl->y;
  303.         clip[2]=drl->x+drl->w; clip[3]=drl->y+drl->h;
  304.         vs_clip(V_handle,1, clip);
  305.         v_bar(V_handle,pnt);
  306.         rl=rl->next;
  307. #if JOHAN_RECTANGLES
  308. #else
  309.         free(drl);
  310. #endif
  311.     }                /* We don't need to re-draw the slider as it get's redrawn by the  */
  312.                     /* standard widget handler anyway. */
  313.     v_show_c(V_handle, 1);
  314.  
  315.     return TRUE;
  316. }
  317.  
  318. /*======================================================
  319.     HORIZONTAL SLIDER WIDGET BEHAVIOUR
  320.     The slider widgets are slightly more complex than other widgets
  321.     as they have three seperate 'widgets' inside them.
  322.     (I know GEM doesn't have these, but I think they're cool)
  323. ========================================================*/
  324.  
  325. short display_hslide(XA_WINDOW *wind, XA_WIDGET *widg)
  326. {
  327.     short x,y,pnt[6],offs,len;
  328.     XA_SLIDER_WIDGET *sl=(XA_SLIDER_WIDGET*)(widg->stuff);
  329.  
  330.     rp_2_ap(wind, widg, &x, &y);    /* Convert relative coords and window location to absolute screen location */
  331.  
  332.     len=(widg->w*sl->length)/1000;
  333.     offs=((widg->w - len)*sl->position)/1000;
  334.  
  335.     if (widg->stat==XAW_PLAIN)
  336.         vsl_color(V_handle,display.dial_colours.t_l_col);
  337.     else
  338.         vsl_color(V_handle,display.dial_colours.b_r_col);
  339.     
  340.     pnt[0]=x+offs; pnt[1]=y+widg->h;
  341.     pnt[2]=x+offs; pnt[3]=y;
  342.     pnt[4]=x+offs+len; pnt[5]=y;
  343.     v_pline(V_handle,3,pnt);
  344.  
  345.     if (widg->stat==XAW_PLAIN)
  346.         vsl_color(V_handle,display.dial_colours.b_r_col);
  347.     else
  348.         vsl_color(V_handle,display.dial_colours.t_l_col);
  349.  
  350.     pnt[2]=x+offs+len; pnt[3]=y+widg->h;
  351.     v_pline(V_handle,3,pnt);
  352.     
  353.     return TRUE;
  354. }
  355.  
  356. short drag_hslide(XA_WINDOW *wind, XA_WIDGET *widg)
  357. {
  358.     short pmx,pmy,mx,my,mb,x,y,wcx;
  359.     short imx,imy,pnt[4],clip[4],offs,noffs,len,dx,orig_offs;
  360.     XA_SLIDER_WIDGET *sl=(XA_SLIDER_WIDGET*)(widg->stuff);
  361. #if JOHAN_RECTANGLES
  362.     XA_RECT_LIST *rl, *drl;
  363. #else
  364.     XA_RECT_LIST *rl=generate_rect_list(wind);
  365.     XA_RECT_LIST *drl;
  366. #endif
  367.  
  368. #if JOHAN_RECTANGLES
  369.     if (!(rl = wind->rl_full))
  370.         rl = wind->rl_full = generate_rect_list(wind);
  371. #endif
  372.  
  373.     rp_2_ap(wind, widg, &x, &y);    /* Convert relative coords and window location to absolute screen location */
  374.     pnt[0]=x; pnt[1]=y;
  375.     pnt[2]=x+widg->w; pnt[3]=y+widg->h;
  376.     vsf_color(V_handle,display.dial_colours.bg_col);
  377.     vsf_interior(V_handle,FIS_SOLID);
  378.  
  379.     len=(widg->w*sl->length)/1000;
  380.     orig_offs=offs=sl->position;
  381.     wcx=widg->click_x-((widg->w - len)*sl->position)/1000;
  382.  
  383.     vq_mouse(V_handle, &mb, &imx, &imy);
  384.     pmx=imx; pmy=imy;
  385.  
  386.     if ((mb)&&((wcx>0)&&(wcx<len)))            /* Drag slider */
  387.     {
  388.         do {
  389.             vq_mouse(V_handle, &mb, &mx, &my);
  390.             if (mx!=pmx)                    /* Has mouse moved? */
  391.             {
  392.                 dx=(1000*(mx-pmx))/(widg->w-len);
  393.                 noffs=offs+dx;
  394.                 if (noffs<0) noffs=0;
  395.                 if (noffs>1000) noffs=1000;
  396.  
  397.                 if (noffs!=offs)            /* Has the slider moved? */
  398.                 {
  399.                     v_hide_c(V_handle);
  400.                     for(drl=rl; drl; drl=drl->next)                /* Walk the rectangle list */
  401.                     {
  402.                         clip[0]=drl->x; clip[1]=drl->y;
  403.                         clip[2]=drl->x+drl->w; clip[3]=drl->y+drl->h;
  404.                         vs_clip(V_handle,1, clip);
  405.                         v_bar(V_handle,pnt);
  406.                     }
  407.                     offs=noffs;
  408.                     sl->position=offs;
  409.                     for(drl=rl; drl; drl=drl->next)                /* Walk the rectangle list */
  410.                     {
  411.                         clip[0]=drl->x; clip[1]=drl->y;
  412.                         clip[2]=drl->x+drl->w; clip[3]=drl->y+drl->h;
  413.                         vs_clip(V_handle,1, clip);
  414.                         display_hslide(wind, widg);
  415.                     }
  416.                     v_show_c(V_handle, 1);
  417.                 }
  418.                 pmx=mx;
  419.             }
  420.         } while(mb);
  421.  
  422.         sl->position=orig_offs;
  423.         send_app_message(wind->owner, WM_HSLID, 0, wind->handle, offs, 0, 0, 0);
  424.     }else{
  425.         vsf_color(V_handle,display.dial_colours.highlight_col);
  426.         if (wcx<0)            /* Page left */
  427.         {
  428.             send_app_message(wind->owner, WM_ARROWED, 0, wind->handle, WA_LFPAGE, 0, 0, 0);
  429.             pnt[0]=x; pnt[1]=y;
  430.             pnt[2]=x+(widg->w - len)*sl->position/1000; pnt[3]=y+widg->h;
  431.         }else{                    /* Page right */
  432.             send_app_message(wind->owner, WM_ARROWED, 0, wind->handle, WA_RTPAGE, 0, 0, 0);
  433.             pnt[0]=x+(widg->w - len)*sl->position/1000+len; pnt[1]=y;
  434.             pnt[2]=x+widg->w; pnt[3]=y+widg->h;
  435.         }
  436.         v_hide_c(V_handle);
  437.         for(drl=rl; drl; drl=drl->next)                /* Walk the rectangle list */
  438.         {
  439.             clip[0]=drl->x; clip[1]=drl->y;
  440.             clip[2]=drl->x+drl->w; clip[3]=drl->y+drl->h;
  441.             vs_clip(V_handle,1, clip);
  442.             v_bar(V_handle,pnt);
  443.             display_hslide(wind, widg);
  444.         }
  445.         v_show_c(V_handle, 1);
  446.         vsf_color(V_handle,display.dial_colours.bg_col);
  447.         if (mb)    /* If the button has been held down, set a pending/active widget for the client */
  448.         {
  449.             set_widget_active(wind, widg, &drag_hslide);
  450.             return FALSE;    /* We return false here so the widget display status stays selected whilst it repeats */
  451.         }
  452.         cancel_widget_active(wind);
  453.     }
  454.     
  455.     v_hide_c(V_handle);
  456.     while(rl)        /* Dispose of the rectangle list & erase the dragged slider */
  457.     {
  458.         drl=rl;
  459.         clip[0]=drl->x; clip[1]=drl->y;
  460.         clip[2]=drl->x+drl->w; clip[3]=drl->y+drl->h;
  461.         vs_clip(V_handle,1, clip);
  462.         v_bar(V_handle,pnt);
  463.         rl=rl->next;
  464. #if JOHAN_RECTANGLES
  465. #else
  466.         free(drl);
  467. #endif
  468.     }                /* We don't need to re-draw the slider as it get's redrawn by the  */
  469.                     /* standard widget handler anyway. */
  470.     v_show_c(V_handle, 1);
  471.  
  472.     return TRUE;
  473. }
  474.